<?php
    session_start();
?>
<?php
    include_once "connection.php";
?>
<?php
    /* 该页面用于获取用户的文章 */
    $user_id = $_SESSION['user_id'];
    $sql = "select post_id, post_title from posts where user_id='".$user_id."'";
    $result = $dbh->query($sql);
    $result->setFetchMode(PDO::FETCH_ASSOC);
    $my_posts = array();
    $i = 0;
    while($row = $result->fetch()){
        $my_posts[$i] = $row;
        $i++;
    }
    $result->closeCursor();
    $length = count($my_posts);

?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="stylesheet" href="css/my_post.css" type="text/css">
        <title>我的文章</title>
    </head>
    <body>
        <div class="outer_wrapper">
            <?php
                if($length == 0){
                    echo "你还没有发表文章哦";
                }
                else {
                    echo '<form method="post" action="delete_post.php">';
                    for($i = $length-1; $i >= 0; $i--){
                        echo '<div class="checkbox"><input type="checkbox" name="my_post[]" value="'.$my_posts[$i]['post_id'].'">'.'<a href="post_read.php?post_id='.$my_posts[$i]['post_id'].'" target="_top">'.$my_posts[$i]['post_title'].'</a></div>';
                    }
                    echo '<input type="submit" class="submit" value="删除"/>';
                }
            ?>
        </div>
    </body>
</html>